package com.guc.md.behavior

import android.content.Context
import android.util.AttributeSet
import android.util.LogPrinter
import android.view.View
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.appbar.AppBarLayout
import com.guc.kframe.utils.LogG
import kotlin.math.abs

/**
 * Created by guc on 2021/5/27.
 * Description： 自定义简书behavior
 */
class BottomBehavior(context: Context, attrs: AttributeSet) :
    CoordinatorLayout.Behavior<TextView>(context, attrs) {

    override fun layoutDependsOn(
        parent: CoordinatorLayout,
        child: TextView,
        dependency: View
    ): Boolean {
        return dependency is AppBarLayout
    }

    override fun onDependentViewChanged(
        parent: CoordinatorLayout,
        child: TextView,
        dependency: View
    ): Boolean {
        val translationY: Float = abs(dependency.top).toFloat()
        child.translationY = translationY
        LogG.loge("BottomBehavior", "translationY:$translationY")
        return true
    }

}